package com.temp.service.impl;

import com.temp.enumeration.EmailType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.thymeleaf.TemplateEngine;
import org.thymeleaf.context.Context;

import java.util.Locale;

@Service
public class StatusNoticeService {
    @Autowired
    private EmailService emailService;

    @Autowired
    private TemplateEngine templateEngine; // Thymeleaf模板引擎

    private static final String WEBSITE_NAME = "Tetheraid";

    public void sendApprovedEmail(String email, String username, EmailType type, String CampaignTitle) {
        Context context = new Context(Locale.CHINA);
        context.setVariable("username", username);
        context.setVariable("campaignTitle", CampaignTitle);

        String emailContent = templateEngine.process(type.getEmailEngine(), context);
        // 发送邮件
        emailService.sendHtml(WEBSITE_NAME, email, type.getEmailName(), emailContent);
    }
}
